<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
/* styles.css */

body {
    font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
    background-color: #ececec;
    color: #333;
    margin: 0;
    padding: 20px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

header, footer {
    background-color: #333;
    color: #fff;
    padding: 10px 20px;
    text-align: left;
}

header h1 {
    margin: 0;
}

main {
    flex: 1;
    padding: 20px;
    background: white;
    margin-top: 20px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#categoryForm {
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
    background: #f9f9f9;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
}

th, td {
    padding: 15px;
    border-bottom: 1px solid #ddd;
    text-align: left;
}

th {
    background-color: #007bff;
    color: white;
}

input[type="text"], input[type="hidden"] {
    width: calc(100% - 22px);
    padding: 10px;
    margin-bottom: 15px;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
}

input[type="button"], button {
    padding: 10px 20px;
    margin-right: 10px;
    border: none;
    border-radius: 4px;
    background-color: #28a745;
    color: white;
    cursor: pointer;
    transition: background-color 0.3s;
}

input[type="button"]:hover, button:hover {
    background-color: #218838;
}

@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    main {
        margin-top: 10px;
    }

    #categoryForm {
        padding: 10px;
    }
}
</style>
</head>
<body>
<main>
    <section id="categoryForm">
			<table>
				<tr>
					<td><label>种类编号</label></td>
					<td><label>${category.category }</label></td>
				</tr>
				<tr>
					<td><label for="categoryName">种类名称</label></td>
					<td><input type="text" name="categoryName" id="categoryName" value="${category.categoryName }"></td>
				</tr>
				<tr>
					<td colspan="2"><input type="button" value="保存" id="sub"></td>
				</tr>
				<tr>
					<td colspan="2"><input type="hidden" value="${category.category }" id="id"></td>
				</tr>	
		</table>
   </section>
</main>
<script src="../js/jquery.min.js"></script>
<script src="../js/layer/layer.js"></script>
<script>
$(document).ready(function() {
    $('#sub').click(function() {
        var id = $('#id').val();
        var categoryName = $('#categoryName').val();
        $.post('AdminUpdateCategoryServlet', {
            id: id,
            categoryName: categoryName
        }, function(response) {
            switch (response) {
                case 'OK':
                    layer.msg('修改成功');
                    move();
                    break;
                case 'Error2':
                    layer.alert('种类名称重复');
                    break;
                default:
                    layer.msg('修改失败');
                    break;
            }
        });
    });

    function move() {
        window.location.href = 'AdminCategoryServlet2';
    }
});
	function move(){
		window.location.href="AdminCategoryServlet2";
	}
</script>
</body>
</html>